package com.jinduplan.planmanager.mvp.model

import com.cxz.kotlin.baselibs.base.getSingleParmerJson
import com.cxz.kotlin.baselibs.mvp.BaseModel
import com.cxz.kotlin.baselibs.utils.GsonHelper
import com.jinduplan.planmanager.bean.*
import com.jinduplan.planmanager.http.MainRetrofit
import com.jinduplan.planmanager.mvp.contract.LoginRegisterContract
import com.jinduplan.planmanager.mvp.contract.MainContract
import io.reactivex.rxjava3.core.Observable
import okhttp3.RequestBody

/**
 * @author admin
 * @date 2018/11/20
 * @desc
 */
class LoginRegisterModel : BaseModel(), LoginRegisterContract.Model {


    override fun login(username: String, password: String): Observable<HttpResult<LoginInfo>> {
        val map = HashMap<String,String>()
        map.put("username",username)
        map.put("password",password)
        return MainRetrofit.service.login(GsonHelper.getRequestBoby(map))
    }

    override fun loginWithSms(username: String, sms: String): Observable<HttpResult<LoginInfo>> {

        val map = HashMap<String,String>()
        map.put("username",username)
        map.put("password",sms)
        return MainRetrofit.service.login(GsonHelper.getRequestBoby(map))
    }

    override fun register(
        username: String,
        password: String,
        code: String
    ): Observable<HttpResult<LoginInfo>> {
        return MainRetrofit.service.reg(GsonHelper.getRequestBoby(arrayListOf("username","password","code"),arrayListOf(username,password,code)))
    }

    override fun changePsw(
        username: String,
        password: String,
        code: String
    ): Observable<HttpResult<LoginInfo>> {
        return MainRetrofit.service.modifyPassword(GsonHelper.getRequestBoby(arrayListOf("username","password","code"),arrayListOf(username,password,code)))
    }

    override fun smsSend(phone: RequestBody): Observable<HttpResult<Any>> {
        return MainRetrofit.service.smsSend(phone)

    }




}